<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="author" content="王佳佳">
    <title>测试</title>
    <style>
        *
        {
            box-sizing: border-box;
        }
        body
        {
            margin: 0;
        }
        .box
        {
            position: relative;
            width: 300px;
            height: 300px;
            margin: 50px;
            overflow: hidden;  
        }
        .main
        {
            position: absolute;
            width: 600px;
            height: 300px;
        }
        section
        {
            width: 300px;
            height: 300px;
            float: left;
        }
        section:nth-child(1)
        {
            background-color: salmon;
        }
        section:nth-child(2)
        {
            position: absolute;
            background-color: skyblue;
            margin-left: 300px;
        }
        .button
        {
            width: 250px;
            height: 25px;
            margin-left: 90px;
        }
        .pointer
        {
            cursor: pointer;
        }
    </style>
</head>
<body>
<script src="./jquery.js"></script>
    <div class="box">
        <div class="main">
            <section></section>
            <section></section>
        </div>
    </div>
    <div class="button">
        <input class="prev" type="button" name="" value="上一张">
        <input class="next" type="button" name="" value="下一张">
    </div>
</body>
</html>

<script>
window.onload = function()
{
    var isChange = true;
    var timer = setInterval(change,2500);
    function change()
    {
        if(isChange)
        {
            nextimg();
        }
        else
        {
            previmg();
        }
        isChange = !isChange;
    }

    $('.button').hover(function()
        {
            clearInterval(timer);
        },
        function()
        {
            if(timer)
            {
                timer = null;
            }
            timer = setInterval(change,2500);
        });
    function previmg()
    {
        $('.main').stop().animate({marginLeft:0},1000);
        $('.next').css('background-color','skyblue').addClass('pointer')
        .siblings().css('background-color','').removeClass('pointer');
    }
    function nextimg()
    {
        $('.main').stop().animate({marginLeft:-300},1000);
        $('.next').css('background-color','').removeClass('pointer')
        .siblings().css('background-color','salmon').addClass('pointer');
    }
    $('.prev').click(function()
    {
        previmg();
        isChange = !isChange;
    })
    $('.next').click(function()
    {
        nextimg();
        isChange = !isChange;
    })
}
</script>